#include <iostream>
#include "cliUtil.h"

using namespace std;
#define OUTLEN 255

string& trim(string &s) 
{
    if (s.empty()) 
    {
        return s;
    }

    s.erase(0,s.find_first_not_of(" "));
    s.erase(s.find_last_not_of(" ") + 1);
    return s;
}

void split(string& s, string& delim, vector<string>* ret)  
{  
    size_t last = 0;  
    size_t index=s.find_first_of(delim,last);  
    while (index!=string::npos)  
    {  
        ret->push_back(s.substr(last,index-last));  
        last=index+1;  
        index=s.find_first_of(delim,last);  
    }  
    if (index-last>0)  
    {  
        ret->push_back(s.substr(last,index-last));  
    }  
}  


bool getCnString(string keyName, string &keyVal )
{
    char buf_o[OUTLEN];
    FILE *fp;

    if( (fp=fopen("strMap.txt","r" ))==NULL ){
        cout << "Can NOT open file" << endl;
        return false;
    }


    while( !feof(fp) && fgets( buf_o, OUTLEN, fp )!=NULL )
    {
        if( strlen(buf_o) <= 0 ) continue;

        string nameValStr(buf_o);
        //cout << nameValStr << endl;
        int delim = nameValStr.find('=');
        
        if(delim<0) continue;

        if(nameValStr.substr(0, delim)==keyName)
        {
            keyVal = nameValStr.substr(delim+1, nameValStr.length()-delim-3);
            return true;
        }
    }
    return false;
}
